<h2>首页设置 - <?php echo $setting->label; ?></h2>

<ul class="button">
    <?php if ($id != 8): ?>
        <li><a href="javascript:void(0);" class="replace">替换图片</a></li>
    <?php endif; ?>
    <li><a href="javascript:void(0);" class="edit">修改<?php echo $value_label; ?></a></li>
</ul>

<a href="javascript:void(0);">
    <img src="/assets/uploads/setting/setting-<?php echo $setting->id; ?>.jpg"/>
</a>

<p><?php echo $setting->link; ?></p>
<p><?php echo $setting->content; ?></p>
<p><?php echo $setting->content_en; ?></p>

<script id="replace-form-template" type="text/x-jquery-tmpl">
    <form action="/backend/photo/replace" method="post" enctype="multipart/form-data" target="upload-iframe">
	<input type="hidden" name="path" value="setting"/>
	<input type="hidden" name="image_name" value="setting-<?php echo $id; ?>"/>
	<input type="file" name="image"/>
	<input type="submit" value="替换" name="submit"/>
    </form>
    <iframe name="upload-iframe" style="width:0;height:0;display: none;"></iframe>
</script>


<script id="edit-form-template" type="text/x-jquery-tmpl">
    <form action="/backend/setting/update" method="post">
	<input type="hidden" name="id" value="<?php echo $setting->id; ?>"/>
	<?php if ($setting->id != 8): ?>
    	<div class="form-row">
    	    <label for="link">链接</label>
    	    <input type="text" class="text" name="link" value="<?php echo $setting->link; ?>"/>
    	</div>
	<?php endif; ?>
	<?php if (in_array($setting->id, array(1, 2, 8))): ?>
	    <?php if ($setting->id != 8): ?>
		<div class="form-row">
		    <span>首页显示</span>
		    <input type="checkbox" class="checkbox" name="display" value="1"/>
		</div>
	    <?php endif; ?>
    	<div class="form-row">
    	    <label for="content">中文</label>
    	    <textarea cols="50" rows="3" name="content" style="width:100%;"><?php echo $setting->content; ?></textarea>
    	</div>
    	<div class="form-row">
    	    <label for="content_en">英文</label>
    	    <textarea cols="50" rows="3" name="content_en" style="width:100%;"><?php echo $setting->content_en; ?></textarea>
    	</div>
	<?php endif; ?>
	<input type="submit" name="submit" value="提交"/>
    </form>
</script>

<script type="text/javascript">
    $(function(){
	window.uploadCallback = function(status,msg,data){
	    switch(status){
		case 'XT001':
		    if(msg!=''){
			Z.tip(msg,2);
		    }
		    window.location.reload();
		    break;
		case 'XT002':
		    Z.alert(msg||'操作失败');
		    break;
		case 'XT003':
		    Z.alert('您不具备此操作权限');
		    break;
		case 'XT004':
		    Z.alert('请先登录');
		    break;
		default:
		    Z.alert('未知错误!');
                  
	    };
	};
	
	$('a.replace').click(function(){
	    Z.alert($('#replace-form-template').html());
	});
	
	$('a.edit').click(function(){
	    Z.form({
		content: $('#edit-form-template').html(),
		success: function(){
		    window.location.reload();
		}
	    });
	});
    });
</script>
<style type="text/css">
    .form-row label{float: none;text-align: left;}
    .form-row input.checkbox{width:auto;border:none;outline: none;vertical-align: middle;}
    .form-row input.text,.form-row textarea{width:100%;padding:0;}
    .form-row textarea{height:6em;}
</style>